package com.oba.base.convertor;

import java.util.HashMap;
import java.util.Map;

public class ConvertUtil {
	static private Map<Class<? extends Object>, Convertor> converterMap;
	static {
		converterMap = new HashMap<Class<? extends Object>, Convertor>();
		converterMap.put(Integer.class, new IntegerConvertor());
		converterMap.put(Long.class, new LongConvertor());
		converterMap.put(short.class, new ShortConvertor());
		converterMap.put(Boolean.class, new BooleanConvertor());
	}

	public static Object convert(Class<? extends Object> toCls, String inputStr) {
		if (toCls == String.class || inputStr == null)
			return inputStr;
		else
			return converterMap.get(toCls).getAsObject(inputStr);
	}
}
